<?php
class Zendvn_Filter_FileName implements Zend_Filter_Interface{
	
	public function filter($value, $options = null){
		
		$filter = new Zend_Filter();
        $filter->addFilter(new Zend_Filter_StringToLower(array('encoding'=>'utf-8')))
        		->addFilter(new Zend_Filter_PregReplace('#\.[^.]+$#',''))
			   	->addFilter(new Zendvn_Filter_Utf8())
			   	->addFilter(new Zend_Filter_StringTrim())
				->addFilter(new Zend_Filter_Alnum(true))
				->addFilter(new Zend_Filter_PregReplace('#\s+#','_'));
				
		$newValue = $filter->filter($value);
		if($options['length']){
			if(strlen($newValue) > $options['length']){
				$newValue = substr($newValue, 0, $options['length']);
			}
		}
		return $newValue;
	}
	
}